//
// Created by Administrator on 2024/7/6.
// 链表反转
//

#include <iostream>
#include "linkedListUtil.h"
using namespace std;

Node * reverse(Node * head)
{
    Node * pre=nullptr;
    head = head->next;
    Node *cur;
    while(head)
    {
        cur=head->next;
        head->next=pre;
        pre=head;
        head=cur;
    }
    return new Node{0,pre};
}
int main()
{
    vector<int> v {1,2,3,4,5,6,7,8};
    Node *h = build(v);
    printLinkedList(h);
    h = reverse(h);
    printLinkedList(h);
    return 0;
}